package com.lzk.springboot.demo.utilservice;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Slf4j(topic= "ServiceLogger")
@Service
public class RedisSerivceUtil {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    public String getRightFromRedis(String key){
        String basePushMsg = (String) stringRedisTemplate.opsForList().rightPop(key ,50,TimeUnit.SECONDS);
        if(null == basePushMsg){
            return null;
        }else{
            return basePushMsg;
        }
    }
    public void setLeftForRedis(String key,String basePushMsg){
        Long index = stringRedisTemplate.opsForList().leftPush(key,basePushMsg);
        log.info("redisTemplate message is : {} , return result: {}" ,basePushMsg,index);

    }
}
